#ifndef CSUPERLEADWRAPPER_H_
#define CSUPERLEADWRAPPER_H_

#include <QObject>
#include "SerialCommand/ISerialCommand.h"
#include "SerialCommand/CSerialCommandControllor.h"

class CSerialCommandWrapper :
        public QObject,
        public zl::zlmodules::ISerialCommandEventNotice
{
    Q_OBJECT
public:
    CSerialCommandWrapper(QObject* parent = Q_NULLPTR) : QObject(parent) {
        impl_ = new zl::zlmodules::CSerialCommandControllor(this);
    }
    ~CSerialCommandWrapper() {
        impl_->Disconnect();
        delete impl_;
    }

    /// \brief 指令回复信号 下位机接收指令后 立刻回复指令接收到 下位机是否执行
    inline void CommandResult(const unsigned char& cmd, zl::zlmodules::CommandResultType type, const unsigned char* data, size_t len) override
    { emit commandResult(cmd, type, QByteArray((const char*)data, len)); }

    /// \brief 消息回复信号 下位机接收指令 执行完成后 回复执行结果
    virtual void MsgData(const unsigned char& cmd, const unsigned char* data, size_t len) override
    {
        emit msgData(cmd, QByteArray((const char*)data, len));
    }

public slots:

    /// \brief 打开串口连接
    inline qint32 connect(const QString& port, qint32 baud) { return impl_->Connect(port.toStdString(), baud); }

    /// \brief 关闭串口连接
    inline void disconnect() { impl_->Disconnect(); }

    /// \brief 关闭开关电源 n秒后重启
    inline qint32 ResetSwitchPowerCommand(zl::zlmodules::SwitchType switch_type, int32_t seconds) { return impl_->ResetSwitchPowerCommand(switch_type, seconds); }

signals:

    /// \brief 指令回复信号 下位机接收指令后 立刻回复指令接收到 下位机是否执行
    void commandResult(const unsigned char cmd, zl::zlmodules::CommandResultType type, QByteArray data);

    /// \brief 消息回复信号 下位机接收指令 执行完成后 回复执行结果
    void msgData(const unsigned char cmd, QByteArray data);
private:
    zl::zlmodules::ISerialCommand* impl_;

};

#endif // CSUPERLEADWRAPPER_H_
